home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_01_01
/
1n01079a
< prev
next >
Wrap
Text File
|
1990-05-16
|
701b
|
42 lines
#include "stdio.h"
struct complex
{
double real, imag;
};
struct complex cplx_add(struct complex a, struct complex b);
int cplx_print(struct complex c);
int main()
{
struct complex c1, c2, c3;
c1.real = 1.5;
c1.imag = 0.0;
c2.real = 7.1;
c2.imag = 8.0;
c3 = cplx_add(c1,c2);
cplx_print(c3);
return 0;
}
struct complex cplx_add(struct complex a, struct complex b)
{
struct complex result;
result.real = a.real + b.real;
result.imag = a.imag + b.imag;
return result;
}
int cplx_print(struct complex c)
{
return printf("(%g%+gi)",c.real,c.imag);
}